package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.Interface.OnItemClickLister;
import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.activity.CategorySmapleActivity;
import com.jss.lanouhn.fristapp.modles.CategorySampleInfo;

/**
 * Created by lanouhn on 16/8/26.
 */
public class CategorySampleSuperAdapter extends RecyclerView.Adapter<CategorySampleSuperAdapter.SampleSuperViewHolder> {
    private Context mContext;
    private CategorySampleInfo categorySampleInfo;


    public CategorySampleSuperAdapter(Context mContext, CategorySampleInfo categorySampleInfo) {
        this.mContext = mContext;
        this.categorySampleInfo = categorySampleInfo;
    }

    @Override
    public SampleSuperViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_rv_sample, null);
        SampleSuperViewHolder holder = new SampleSuperViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SampleSuperViewHolder holder, int position) {
        final CategorySampleInfo.DataBean.CategoriesBean bean =
                categorySampleInfo.getData().getCategories().get(position);
        holder.tv_sample.setText(bean.getName());

        holder.rv_sample.setLayoutManager(new GridLayoutManager(mContext, 3));
        CategorySampleItemAdapter adapter =
                new CategorySampleItemAdapter(mContext, bean.getSubcategories());
        adapter.setOnItemClickLister(new OnItemClickLister() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent=new Intent(mContext,CategorySmapleActivity.class);
                intent.putExtra("smapleId",bean.getSubcategories().get(position).getId()+"");
                intent.putExtra("smapleName",bean.getSubcategories().get(position).getName());
                mContext.startActivity(intent);
            }
        });
        holder.rv_sample.setAdapter(adapter);
    }
    @Override
    public int getItemCount() {
        return categorySampleInfo.getData().getCategories().size();
    }


    public class SampleSuperViewHolder extends RecyclerView.ViewHolder {
        private RecyclerView rv_sample;
        private TextView tv_sample;

        public SampleSuperViewHolder(View itemView) {
            super(itemView);
            tv_sample = (TextView) itemView.findViewById(R.id.tv_item_rv);
            rv_sample = (RecyclerView) itemView.findViewById(R.id.rv_item_rv_sample);
        }
    }


}
